<extend name="Layout/ins_popup" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<div class="popup-frame">
		<div class="popup-header">
			<div class="pull-left">
				<h1>添加部门</h1>
			</div>
			<div class="pull-right">
				<a id="btn_save" class="btn" >确定</a>
				<a id="btn_close" class="btn btn-return">关闭</a>
			</div>
		</div>
		<div class="popup-body">
			<div class="popup-body-scroll">
				<div class="popup-content">
					<form id="form_data" name="form_data" method="post" >
						<input type="hidden" name="id" id="id">
						<input type="hidden" name="flow_type_id" id="flow_type_id" value="{$flow_type.id}">
						<input type="hidden" name="opmode" id="opmode" value="add">
						<input type="hidden" id="confirm" name="confirm" >
						<input type="hidden" id="confirm_name" name="confirm_name" >
						<input type="hidden" id="consult" name="consult" >
						<input type="hidden" id="consult_name" name="consult_name">
						<div class="frame">
							<div class="box col-12">
								
									<label class="col-xs-2 input-label" for="name">名称*：</label>
									
										<input class="input" type="text" id="name" name="name" check="required" info="请输入名称">
									</div>
								</div>
							</div>
						</div>
						<div class="frame">
							<div class="box col-12">
								
									<label class="col-xs-2 input-label" for="sort">审批：</label>
									
										<div id="confirm_wrap" class="input-box">
											<a class="add-on" onclick="popup_flow();"><i class="fa fa-user"></i> </a>
											<div class="wrap" >
												<span class="address_list">{$vo.confirm_name}</span>
												<span class="text" >
													<input class="letter" type="text"  >
												</span>
											</div>
											<div class="search dropdown ">
												<ul class="dropdown-menu"></ul>
											</div>
										</div>
									</div>
								</div>
								
									<label class="col-xs-2 input-label" for="sort">协商：</label>
									
										<div id="consult_wrap" class="input-box">
											<a class="add-on" onclick="popup_flow();"> <i class="fa fa-user"></i> </a>
											<div class="wrap" >
												<span class="address_list">{$vo.consult_name}</span>
												<span class="text" >
													<input class="letter" type="text"  >
												</span>
											</div>
											<div class="search dropdown">
												<ul class="dropdown-menu"></ul>
											</div>
										</div>
									</div>
								</div>
								
									<label class="col-xs-2 input-label" for="sort">排序：</label>
									<div class="input-block col-10">
										<input class="input" type="text" id="sort" name="sort" >
									</div>
								</div>
								
									<label class="col-xs-2 input-label" for="is_del">状态：</label>
									<div class="input-block  x-select col-10">
										<select  class="input" name="is_del" id="is_del">
											<option  value="0">启用</option>
											<option value="1">禁用</option>
										</select>
									</div>
								</div>
								
									<label class="col-xs-2 input-label" for="remark" >备注：</label>
									<div class="input-block" >
										<textarea class="textarea" name="remark" rows="5" class="col-xs-12" ></textarea>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);
		layui.use(['global'], function() {
			var $ = layui.jquery;
			//保存后关闭
			$('#btn_save').on('click', function() {
				$("#opmode").val("add");
				$("#id").val("");
				$("#flow_type_id").val($('#flow_type_id', parent.document).val());

				$("#confirm").val("");
				$("#confirm_wrap  span.address_list span").each(function() {
					$("#confirm").val($("#confirm").val() + $(this).attr("data") + '|');
				});

				$("#confirm_name").val("");
				$("#confirm_name").val($("#confirm_wrap span.address_list").html());

				$("#consult").val("");
				$("#consult_wrap span.address_list span").each(function() {
					$("#consult").val($("#consult").val() + $(this).attr("data") + '|');
				});

				$("#consult_name").val("");
				$("#consult_name").val($("#consult_wrap span.address_list").html());

				var vars = $("#form_data").serialize();
				check_form("form_data", function(ret) {
					if (ret.status == 1) {
						send_ajax("{:url('flow_step')}", vars, function(data) {
							if (data.status) {
								layer.msg(data.info, function() {
									parent.location.reload(true);
									parent.layer.close(index);
								});
							} else {
								layer.msg(data.info);
							}
						});
					} else {
						layer.msg(ret.info);
						ret.dom.focus();
						return false;
					}
				});
			});

			//关闭iframe
			$('#btn_close').click(function() {
				parent.layer.close(index);
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:url('winpop')}", 560, 470);
			});

			$(document).on("dblclick", ".inputbox .address_list b", function() {
				$(this).parent().parent().remove();
			});
		});

		function popup_flow() {
			winopen("{:url('popup/flow')}", 560, 470);
		};

		function popup_condition() {
			$id = $("#id").val();
			if ($id == "") {
				ui_error('请选择工作步骤');
			} else {
				winopen(fix_url("{:url('FlowType/condition')}?step_id=" + $id), 704, 570);
			}
		};

		function save() {

		};

		function del() {
			ui_confirm('确定要删除吗?', function() {
				$("#opmode").val("del");
				send_form("form_data", "", "__SELF__");
			});
		};

		function show_data(result) {
			for (var s in result.data) {
				set_val(s, result.data[s]);
			}
			$("#confirm_wrap span.address_list").html(result.data['confirm_name']);
			$("#consult_wrap span.address_list").html(result.data['consult_name']);
			$('#condition_name').html(result.data['condition_name']);

			$("#opmode").val("edit");
		};

	</script>
</block>